package web.demos.web.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.apache.cxf.transport.http.HTTPConduit;
import org.apache.cxf.transports.http.configuration.HTTPClientPolicy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author gqzdev
 * @date 2021/08/26 15:53
 **/
@Configuration
@Slf4j
public class JaxWsClientConfig {
    public static final String WSD_URL = "http://localhost:8080/service/WebServiceInterface?wsdl";

    @Bean("JaxWsClient")
    public Client client() {
        // 创建动态客户端
        JaxWsDynamicClientFactory clientFactory = JaxWsDynamicClientFactory.newInstance();
		//CommonConstant.PUBLIC_SECURITY_URL为连接的url,如http://10.189.200.170:9201/wharfWebService/services/WharfService?wsdl
        log.info("publicsecurity webService url : {}", WSD_URL);
        //创建client
        Client client = clientFactory.createClient(WSD_URL);
        HTTPConduit conduit = (HTTPConduit) client.getConduit();
        HTTPClientPolicy policy = new HTTPClientPolicy();
        policy.setAllowChunking(false);
        // 连接服务器超时时间 10秒
        policy.setConnectionTimeout(10000);
        // 等待服务器响应超时时间 20秒
        policy.setReceiveTimeout(20000);
        conduit.setClient(policy);
        return client;
    }
}
